package metier;

import java.util.ArrayList;

import javax.persistence.*;

import org.hibernate.*;

import configuration.HibernateUtil;

@Entity
@Table(name="reservation")
public class Reservation {

	@Id
	@Column(name="idreservation")
	private String id;
	
	private static int idRes = 1000;
	
	@Column(name="nomclient")
	private String nomClient;
	
	@Column(name="prenomclient")
	private String prenomClient;
	
	@Column(name="emailclient")
	private String emailClient;
	
	@Column(name="paysclient")
	private String paysClient;
	
	@Column(name="telclient")
	private String telClient;
	
	@Column(name="datereservation")
	private String dateReservation;

	//Constructeur vide pour Hibernate
	public Reservation(){
		super();
	}

	public Reservation(String nomClient, String prenomClient, String emailClient, String paysClient, String telClient){
		String idReservation = nomClient.substring(0, 3)+String.valueOf(idRes);
		idRes ++ ;
		this.id = idReservation;
		this.nomClient = nomClient;
		this.prenomClient = prenomClient;
		this.emailClient = emailClient;
		this.paysClient = paysClient;
		
		String format = "dd/MM/yy H:mm:ss"; 
		java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat( format ); 
		java.util.Date date = new java.util.Date(); 
		
		this.dateReservation = formater.format(date);
	}
	
	public void addReservation(String nomClient, String prenomClient, String emailClient, String paysClient, String telClient){
		Reservation laReservation = new Reservation(nomClient, prenomClient, emailClient, paysClient, telClient);
		
		Session laSession = HibernateUtil.getSession();
		Transaction trans = laSession.beginTransaction();
		laSession.persist(laReservation);
		trans.commit();
		laSession.close();
		
		}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public static int getIdRes() {
		return idRes;
	}

	public static void setIdRes(int idRes) {
		Reservation.idRes = idRes;
	}

	public String getNomClient() {
		return nomClient;
	}

	public void setNomClient(String nomClient) {
		this.nomClient = nomClient;
	}

	public String getPrenomClient() {
		return prenomClient;
	}

	public void setPrenomClient(String prenomClient) {
		this.prenomClient = prenomClient;
	}

	public String getEmailClient() {
		return emailClient;
	}

	public void setEmailClient(String emailClient) {
		this.emailClient = emailClient;
	}

	public String getPaysClient() {
		return paysClient;
	}

	public void setPaysClient(String paysClient) {
		this.paysClient = paysClient;
	}

	public String getTelClient() {
		return telClient;
	}

	public void setTelClient(String telClient) {
		this.telClient = telClient;
	}

	public String getDateReservation() {
		return dateReservation;
	}

	public void setDateReservation(String dateReservation) {
		this.dateReservation = dateReservation;
	}
}
